﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModelLayer;
using DBLayer;
/// <summary>
/// Controller class to handle booking
/// </summary>
namespace CtrLayer
{
    public class BookingCtr
    {
        //Variables initialization
        private AirlineCtr airlineCtr;
        private PlaneCtr planeCtr;
        private FlightInstanceDB flightInstanceDb;
        private SeatBookingDB seatBookingDb;
        private TravelDB travelDb;
        private SeatDB seatDb;


        //constructor
        public BookingCtr()
        {
            planeCtr = new PlaneCtr();
            airlineCtr = new AirlineCtr();
            flightInstanceDb = new FlightInstanceDB();
            seatBookingDb = new SeatBookingDB();
            seatDb = new SeatDB();
            travelDb = new TravelDB();
        }
        #region FlightInstance
        //insert flightInstance
        public int InsertFlightInstance(FlightInstance _flightInstance)
        {
            return flightInstanceDb.InsertFlightInstance(_flightInstance);
        }
        //check is two airports has a valid conncetion
        public bool HasValidConnection(Airport _startAirport, Airport _endAirport, DateTime _flightDate)
        {
            return flightInstanceDb.HasValiedConnection(_startAirport, _endAirport, _flightDate);
        }
        //Find flightInstance by flight
        public List<FlightInstance> FindFlightInstanceByFlight(Flight _flight)
        {
            return flightInstanceDb.FindFlightInstanceByFlight(_flight);
        }
        //Find 
        public List<FlightInstance> FindNextFlightInstanceByFlight(Flight _flight, DateTime _flightDate)
        {
            return flightInstanceDb.FindNextFlightInstanceByFlight(_flight, _flightDate);
        }
        public FlightInstance ValidNextLink(Flight _flight, DateTime _flightTime)
        {
            return flightInstanceDb.ValidNextLink(_flight, _flightTime);
        }

        public FlightInstance FindFlightInstanceById(int _id)
        {
            return flightInstanceDb.FindFlightInstanceById(_id);
        }
        public List<FlightInstance> FindFlightInstancesByFlightAndDate(Flight _flight, DateTime _date)
        {
            return flightInstanceDb.FindFlightInstanceByFlightAndDate(_flight, _date);
        }
        public List<FlightInstance> SelectAllFlightInstances()
        {
            return flightInstanceDb.SelectAll();
        }
        public int RemoveFlightInstance(FlightInstance _flightInstance)
        {
            return flightInstanceDb.RemoveFlightInstance(_flightInstance);
        }
        public int UpdateFlightInstance(FlightInstance _flightInstance)
        {
            return flightInstanceDb.UpdateFlightInstance(_flightInstance);
        }
        public List<Seat> FindFreeSeats(FlightInstance _flightinstance)
        {
            return seatDb.FindFreeSeatsByFlightInstance(_flightinstance);

        }
        #endregion
        #region SeatBooking
        public int InsertSeatBooking(SeatBooking _seatBooking, int _travelId)
        {
            return seatBookingDb.InsertSeatBooking(_seatBooking, _travelId);
        }
        public int RemoveSeatBooking(SeatBooking _seatBooking)
        {
            return seatBookingDb.RemoveSeatBooking(_seatBooking);
        }
        public SeatBooking FindSeatBookingByFlightAndSeat(FlightInstance _flightinstance, Seat _seat)
        {
            return seatBookingDb.FindSeatBookByFlightAndSeat(_flightinstance, _seat);
        }
        public int UpdateSeatBooking(SeatBooking _seatBooking)
        {
            return seatBookingDb.UpdateSeatBooking(_seatBooking);
        }
        public List<SeatBooking> SelectAllSeatBookings()
        {
            return seatBookingDb.SelectAllSeatBookings();
        }
        public List<Seat> SelectFreeSeats(FlightInstance _flightInstance)
        {
            return seatDb.FindFreeSeatsByFlightInstance(_flightInstance);
        }
        #endregion
        #region Travel
        public int InsertTravel(Travel _travel)
        {
            return travelDb.InsertTravel(_travel);
        }
        public Travel FindTravel(int _travelId)
        {
            return travelDb.FindTravel(_travelId);
        }
        public int UpdateTravel(Travel _travel)
        {
            return travelDb.UpdateTravel(_travel);
        }
        public List<Travel> SelectAllTravels()
        {
            return travelDb.SelectAll();
        }
        public int RemoveTravel(Travel _travel)
        {
            return travelDb.RemoveTravel(_travel);
        }

        #endregion

        public void gTest()
        {
            flightInstanceDb.TestDataInsert();
        }
    }
}
